class Solution {
    public int minStoneSum(int[] piles, int k) {
        // 优先队列
        int n = piles.length;
        PriorityQueue<Integer> pque = new PriorityQueue<>((a,b)->b-a);
        Arrays.sort(piles);
        int res = 0;
        for(int i = 0;i < n;i++) {
            pque.offer(piles[i]);
            res+=piles[i];
        }
        for(int i = 0;i < k;i++) {
            int x = pque.poll();
            res-=x/2;
            pque.offer(x - x/2);
        }
        return res;
    }
}

